package com.wanghengzhi.design.patterns.chain;

abstract class AbstractLogger {

    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    protected int level;

    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger logger) {
        this.nextLogger = logger;
    }

    public void logMsg(int level, String message) {
        if (this.level < level) {
            write(message);
        }

        if (nextLogger != null) {
            nextLogger.logMsg(level, message);
        }
    }

    abstract void write(String message);
}
